precision mediump float;

uniform sampler2D uSampler;
uniform vec2 uCenter;     // 方框中心 (0~1)
uniform vec2 uSize;       // 方框宽高 (0~1)
uniform float uBorder;    // 边框厚度 (0~0.05 建议)
uniform vec4 uColor;      // 边框颜色
uniform vec2 uResolution; // 分辨率

varying vec2 vTextureCoord;

void main() {
  vec2 halfSize = uSize * 0.5;
  vec2 minPos = uCenter - halfSize;
  vec2 maxPos = uCenter + halfSize;

  bool insideX = (vTextureCoord.x >= minPos.x && vTextureCoord.x <= maxPos.x);
  bool insideY = (vTextureCoord.y >= minPos.y && vTextureCoord.y <= maxPos.y);

  bool borderX = (abs(vTextureCoord.x - minPos.x) < uBorder ||
                  abs(vTextureCoord.x - maxPos.x) < uBorder);
  bool borderY = (abs(vTextureCoord.y - minPos.y) < uBorder ||
                  abs(vTextureCoord.y - maxPos.y) < uBorder);

  if ((insideX && borderY) || (insideY && borderX)) {
    gl_FragColor = uColor; // 画边框
  } else {
    gl_FragColor = texture2D(uSampler, vTextureCoord); // 原始图像
  }
}
